import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
//import 'package:tobias/tobias.dart' as tobias;
import 'function.dart';

class RechargePage extends StatefulWidget {
  RechargePage(this.mainColor);
  final Color mainColor;
  @override
  _RechargePageState createState() => _RechargePageState();
}

class _RechargePageState extends State<RechargePage> {
  alipay(double amount) async {
    toast("充值请联系作者");
//    var uid = await getStorage("uid");
//    var url = "https://www.fmtol.com/Home/Pay/alipay";
//    Map data = {
//      "total": amount,
//      "subject": "点数充值",
//      "uid": uid,
//    };
//    print(data);
//    var res = await get(url, data, null, decode: false);
//    print(res);
//    var result = await tobias.pay(res);
//    print(result['result']);
//    print(result);
//    if (result != null &&
//        result['alipay_trade_app_pay_response']['code'] == "10000") {
//      print(result['alipay_trade_app_pay_response']['trade_no']);
//      var trade_no = result['alipay_trade_app_pay_response']['trade_no'];
//      var payRes = await checkPay(uid, trade_no);
//      print(payRes);
//    } else {
//      print(result['alipay_trade_app_pay_response']['code']);
//    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: new CupertinoNavigationBar(
        actionsForegroundColor: Colors.white,
        backgroundColor: widget.mainColor,

        middle: new Text(
          "点数充值",
          style: new TextStyle(
            color: Colors.white,
            fontWeight: FontWeight.normal,
          ),
        ),
        trailing: new CupertinoButton(
          padding: EdgeInsets.zero,
          child: new Text(
            "充值记录",
            style: new TextStyle(fontSize: 16.0, color: Colors.white),
          ),
          pressedOpacity: 0.8,
          minSize: 24.0,
          onPressed: () {},
        ),
      ),
      body: new Column(
        children: <Widget>[
          new ListTile(
            title: new Text("1元"),
            trailing: new Text("100点数"),
            onTap: () {
              alipay(1.0);
            },
          ),
          new ListTile(
            title: new Text("5元"),
            trailing: new Text("500点数"),
            onTap: () {
              alipay(5.0);
            },
          ),
          new ListTile(
            title: new Text("10元"),
            subtitle: new Text("赠送10%"),
            trailing: new Text("1100点数"),
            onTap: () {
              alipay(10.0);
            },
          ),
          new ListTile(
            title: new Text("20元"),
            subtitle: new Text("赠送20%"),
            trailing: new Text("2400点数"),
            onTap: () {
              alipay(20.0);
            },
          ),
          new ListTile(
            title: new Text("50元"),
            subtitle: new Text("赠送50%"),
            trailing: new Text("7500点数"),
            onTap: () {
              alipay(50.0);
            },
          ),
          new ListTile(
            title: new Text("100元"),
            subtitle: new Text("赠送100%"),
            trailing: new Text("20000点数"),
            onTap: () {
              alipay(0.01);
            },
          ),
        ],
      ),
    );
  }
}
